package com.zking.utils.廖全箐;

import com.zking.dao.EvaluateDao;
import com.zking.dao.FoodDao;
import com.zking.entity.Food;
import com.zking.frame.Backstage;
import com.zking.frame.Client;
import com.zking.frame.Upate;
import com.zking.utils.Tool工具;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class Evaluate extends JFrame {


    private  JButton jButton;

    private JPanel j;

    public  JPanel getEvaluate(String shopName,JFrame jFrame,JScrollPane jScrollPane) {
        Tool工具 tool工具 = new Tool工具();
        List<com.zking.entity.Evaluate> evaluates = new ArrayList<com.zking.entity.Evaluate>();
        EvaluateDao evaluateDao = new EvaluateDao();
        evaluates = evaluateDao.queryEvaluates(shopName);
        JPanel jpanel = new JPanel();
        jpanel.setPreferredSize(new Dimension(590, 10 + 310 * evaluates.size()));
        jpanel.setLayout(null);

        if (evaluates.size() != 0) {
            for (int a = 0; a < evaluates.size(); a++) {
                JPanel jPanel = new JPanel();
                jPanel.setBounds(0, 10 + 310 * a, 1160, 300);
                jPanel.setLayout(null);
                jPanel.setBackground(Color.white);
                JLabel jLabel = new JLabel("用户：");
                jLabel.setBounds(0, 0, 100, 50);
                jLabel.setFont(new Font("黑体", Font.BOLD, 20));
                jPanel.add(jLabel);

                JLabel jLabel0 = new JLabel("星级评价:");
                jLabel0.setBounds(400,0,200,50);
                jLabel0.setFont(new Font("黑体", Font.BOLD, 20));
                jPanel.add(jLabel0);

                jButton = new JButton("回复");
                jButton.setForeground(Color.black);
                jButton.setBounds(900, 10, 100, 40);
                jButton.setFont(new Font("黑体", Font.BOLD, 15));
                jPanel.add(jButton);
                String string = evaluates.get(a).getContent();
                String time = evaluates.get(a).getTime();
                jButton.addActionListener(new AbstractAction() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        new Reply(jFrame,true,"商家回复",string,time);
                        jScrollPane.setViewportView(getEvaluate(shopName,jFrame,jScrollPane));
                        jButton.setText("添加菜品");
                        // 加载并刷新面板
                        jScrollPane.repaint();
                        jScrollPane.updateUI();
                        jScrollPane.revalidate();
                    }
                });

                JLabel jLabel1 = new JLabel(evaluates.get(a).getUsername());
                jLabel1.setBounds(60, 0, 290, 50);
                jLabel1.setFont(new Font("黑体", Font.BOLD, 30));
                jPanel.add(jLabel1);

                JLabel jLabel2 = new JLabel(evaluates.get(a).getStar());
                jLabel2.setBounds(500, 0, 250, 50);
                jLabel2.setFont(new Font("黑体", Font.BOLD, 30));
                jPanel.add(jLabel2);

                TextArea textArea = new TextArea(evaluates.get(a).getContent());
                textArea.setBounds(10, 60, 1100, 190);
                textArea.setFont(new Font("黑体", Font.BOLD, 20));
                textArea.setEditable(false);
                textArea.setBackground(Color.white);
                jPanel.add(textArea);

                JLabel jLabel3 = new JLabel("评价时间：" + evaluates.get(a).getTime(), 0);
                jLabel3.setBounds(300, 250, 590, 30);
                jLabel3.setForeground(Color.GRAY);
                jPanel.add(jLabel3);
                jpanel.add(jPanel);



            }

        }
        return jpanel;
    }


}
